<%@page import="java.sql.*"%>
<%@page import="org.barman.dao.UserDAO"%>
<%@page import="org.barman.pojo.User"%>

<%@include file="/layout/header.jspf"%>


<%
	String action = request.getParameter("action");
	request.setAttribute("action", action);
	
	String id = request.getParameter("id");
	request.setAttribute("id", id);
	
	String username = "";
	String password = "";
	String firstname = "";
	String lastname = "";
	String email = "";
	
	
	if ("edit".equals(action) && Integer.parseInt(id)>0) {
		UserDAO userDAO = new UserDAO();
		User user = userDAO.get(Integer.parseInt(id));
		
		username = user.getUsername();
		password = user.getPassword();
		firstname = user.getFirstName();
		lastname = user.getLastName();
		email = user.getEmail();
	}
%>
<h1>Add/Edit user</h1>
<br>
<form action="../ManageUserServlet?action=${action}&id=${id}" method="post">
	<table align="center">
		<tr>
			<td><b>Username:</b></td>
			<td><input name="username" type="text" value="<%=username%>" /></td>
		</tr>
		<tr>
			<td><b>Password:</b></td>
			<td><input name="password" type="password" value="<%=password%>" /></td>
		</tr>
		<tr>
			<td><b>Verify password:</b></td>
			<td><input name="verifyPassword" type="password" value="<%=password%>" /></td>
		</tr>
		<tr>
			<td><b>E-mail:</b></td>
			<td><input name="email" type="email" value="<%=email%>" /></td>
		</tr>
		<tr>
			<td><b>First name:</b></td>
			<td><input name="firstName" type="text" value="<%=firstname%>" /></td>
		</tr>
		<tr>
			<td><b>Last name:</b></td>
			<td><input name="lastName" type="text" value="<%=lastname%>" /></td>
		</tr>
		<tr>
			<td><b>Role:</b></td>
			<td><select name="role" style="width: 150px;">
					<option value="waiter">waiter</option>
					<option value="barman">barman</option>
					<option value="manager">manager</option>
			</select></td>
		</tr>
		<tr>
			<td colspan="2">
			<br>
			<input type="submit" value="Save User" /></td>
		</tr>
	</table>
</form>
<%@include file="/layout/footer.jspf"%>
